package com.geek.factory.security;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 手机号验证码认证Token
 */
public class PhoneCodeAuthenticationToken extends AbstractAuthenticationToken {

    private final String phone;
    private final String code;
    private Object principal;

    /**
     * 用于认证的构造函数
     */
    public PhoneCodeAuthenticationToken(String phone, String code) {
        super(null);
        this.phone = phone;
        this.code = code;
        setAuthenticated(false);
    }

    /**
     * 用于认证成功后的构造函数
     */
    public PhoneCodeAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.phone = null;
        this.code = null;
        setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return code;
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }

    public String getPhone() {
        return phone;
    }

    public String getCode() {
        return code;
    }
}